#include <iostream>
using namespace std;

const int kMaxN = 1e5 + 10;

int h[kMaxN];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, ans = 0;

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  for (int i = 1; i <= n; i++) {
    ans += max(h[i] - h[i - 1], 0);
  }
  cout << ans << "\n";
  return 0;
}